import { useState } from "react";
import prompt from "vendor/utils/prompt";
import { updatePassword } from '../api'

export const useModifyPassword = () => {
    const [ saving, setSaving ] = useState(false);

    const submit = (oldPassword: string, newPassword: string) => {
        setSaving(true)
        updatePassword(oldPassword, newPassword).then(() => {
            prompt.success("修改成功")
            setSaving(false)
        }).catch(() => setSaving(false))
    }

    return { saving, submit }
}
